//
//  RegistrationViewController.m
//  安好
//
//  Created by lianchuang on 14-11-10.
//  Copyright (c) 2014年 lianchuangbrother. All rights reserved.
//

#import "RegistrationViewController.h"
#import "RegistrationCell.h"
#import "QuickRegViewController.h"
@interface RegistrationViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation RegistrationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeNavBar];
    [self loadData];
    [self makeTableView];
}
#pragma mark - 导航条设置
-(void)makeNavBar
{
    self.navigationItem.title = @"挂号";
    //左按钮--返回
    UIBarButtonItem *backBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"公用_返回.png"] style:UIBarButtonItemStylePlain target:self action:@selector(backClicked)];
    [backBtnImg setTintColor:[UIColor whiteColor]];
    self.navigationItem.leftBarButtonItem = backBtnImg;
    //右按钮-- “挂号记录”
    UIBarButtonItem *recordBtnImg = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"发现_挂号病单.png"] style:UIBarButtonItemStylePlain target:self action:@selector(recordBtnClicked)];
    [recordBtnImg setTintColor:[UIColor whiteColor]];
    self.navigationItem.rightBarButtonItem = recordBtnImg;
}
/**
 * 返回
 */
-(void)backClicked
{
    [self.navigationController popViewControllerAnimated:YES];
}
/**
 *  触发进入 挂号记录
 */
-(void)recordBtnClicked
{
    
}
#pragma mark - 加载数据
-(void)loadData
{
   self.registrationTypes = @[@"快速挂号",@"分类挂号",@"特需挂号"];
}
#pragma mark - 创建tableView 设置代理添加头视图
-(void)makeTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-iOS7TopMargin)];
    [self.view addSubview:self.tableView];
    self.tableView.backgroundColor = [ClassMethodsViewController colorWithHexString:BACK_BACKGROUNDCOLOR_16];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    //隐藏横向和竖向的滑条
    self.tableView.showsHorizontalScrollIndicator = NO;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self makeTableHeaderView];
}
-(void)makeTableHeaderView
{
    //添加头视图 -
    self.headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 100+10)];
    self.headerView.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1];
    self.tableView.tableHeaderView = self.headerView;
    //
    self.headerBtnView = [UIButton buttonWithType:UIButtonTypeCustom];
    self.headerBtnView.frame = CGRectMake(0, 0, kScreenWidth, 100);
    //设置这个贴图Btn 不可点
    self.headerBtnView.userInteractionEnabled = NO;
    [self.headerBtnView setImage:[UIImage imageNamed:@"挂号_横幅.png"] forState:UIControlStateNormal];
    [self.headerView addSubview:self.headerBtnView];
}
#pragma mark - tableView的代理方法
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.registrationTypes.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RegistrationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
    if (cell == nil) {
        cell = [[[NSBundle mainBundle] loadNibNamed:@"RegistrationCell" owner:self options:nil] lastObject];
    }
    cell.registrationLable.text = self.registrationTypes[indexPath.row];
    [cell.accessoryTypeImgView setImage:[UIImage imageNamed:@"公用_跳转.png"]];
    cell.topLineView.backgroundColor = [ClassMethodsViewController colorWithHexString:LINE_BACKGROUNDCOLOR_16];
    cell.bottomLineView.backgroundColor = [ClassMethodsViewController colorWithHexString:LINE_BACKGROUNDCOLOR_16];
    //只有首行cell有top线，全长
    if (indexPath.row != 0)
    {
        cell.topLineView.hidden = YES;
    }
    else
    {
        cell.topLineView.hidden = NO;
        cell.topLineView.frame = CGRectMake(0, 0, kScreenWidth, 0.5);
    }
    //只有末行cell的bottom线全长，其余行不是全长
    if (indexPath.row == self.registrationTypes.count-1  )
    {
        cell.bottomLineView.frame = CGRectMake(0, 43, kScreenWidth, 0.5);
    }
    else
    {
        cell.bottomLineView.frame = CGRectMake(15, 43, kScreenWidth-20, 0.5);
    }
    
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0){
        QuickRegViewController * quickViewController = [[QuickRegViewController alloc]init];
        [self.navigationController pushViewController:quickViewController animated:YES];
    }
}

@end
